package com.readhacker.handler.exception;

import com.readhacker.Result;
import com.readhacker.ResultInfo;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @Author: ReadHacker
 * @Date: 2022年07月06日 09:28
 * @Description:
 **/
@ControllerAdvice
public class GlobalException {

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Result exception(Exception e) {
        e.printStackTrace();
        return Result.error().codeAndMessage(ResultInfo.GLOBAL_ERROR);
    }

    @ExceptionHandler(MyRuntimeException.class)
    @ResponseBody
    public Result myRuntimeException(MyRuntimeException e) {
        e.printStackTrace();
        return Result.error().codeAndMessage(e.getCode(), e.getMessage());
    }
}